package com.mi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mi.entity.MyPages;
import com.mi.entity.UserEntity;
import com.mi.mapper.UserMapper;
import com.mi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class UserServiceImpl implements UserService {

    @Autowired(required = false)
    UserMapper userMapper;

    //用户登录
    @Override
    public UserEntity login(UserEntity ue) {
        return userMapper.login(ue);
    }

    //用户名唯一校验
    @Override
    public UserEntity uniqueName(String uname) {
        return userMapper.uniqueName(uname);
    }


    //用户注册
    @Override
    public boolean regist(UserEntity ue) {
        return userMapper.regist(ue);
    }


    /**
     * 查询会员
     * @param userInfo
     * @return
     */
    public MyPages<UserEntity> queryCustomer(UserEntity userInfo){
        PageHelper.startPage(userInfo.getPageNum(),userInfo.getPageSize());
        List<UserEntity> userEntities = userMapper.queryCustomer(userInfo);
        PageInfo<UserEntity> pageInfo = new PageInfo<>(userEntities);
        MyPages<UserEntity> userEntityMyPages = new MyPages<>();
        userEntityMyPages.setList(pageInfo.getList());
        userEntityMyPages.setPageNum(pageInfo.getPageNum());
        userEntityMyPages.setPageSize(pageInfo.getPageSize());
        userEntityMyPages.setPages(pageInfo.getPages());
        userEntityMyPages.setPageCount((int)pageInfo.getTotal());
        return userEntityMyPages;
    }

    /**
     * 查询单个会员
     * @param userInfo
     * @return
     */
    public UserEntity queryUser(UserEntity userInfo){
        List<UserEntity> userEntities = userMapper.queryCustomer(userInfo);
        if (userEntities==null||userEntities.size()==0){
            return null;
        }
        return userEntities.get(0);
    }

    /**
     * 修改会员
     * @param userInfo
     * @return
     */
    public boolean updCustomer(UserEntity userInfo){
        return userMapper.updCustomer(userInfo);
    }

    /**
     * 删除会员
     * @param uids
     * @return
     */
    public boolean delCustomer(String[] uids){
        return userMapper.delCustomer(uids);
    }

    /**
     * 更改会员状态
     * @param userInfo
     * @return
     */
    public boolean updCustomerStatus(UserEntity userInfo){
        return userMapper.updCustomerStatus(userInfo);
    }

    /**
     * 修改密码
     * @param userInfo
     * @return
     */
    public boolean updPass(UserEntity userInfo){
        return userMapper.updPass(userInfo);
    }
}
